
announcement = jQuery.noConflict();

announcement().ready(function() {

	/* var addNewSpan = '<span id="errormsg_container"></span>';
        announcement("#announcements-node-form").before(addNewSpan);*/
	
  announcement("#announcements-node-form").validate({
										/* onfocusout: false,
  										 onkeyup: false,
  										 onclick: false,*/
										 //debug:true,
										 
					rules: {
						'field_anndept[und]': { 
							required: true,
							maxlength: 255,
							chkbadchar:true,
							valuenotequals: '_none',
						},
						'field_ann_org[und]': { 
							required: true,
							maxlength: 255,
							chkbadchar:true,
							valuenotequals: '_none',
						},
						'field_anndist[und][]':{
							//required: true,
							//maxlength: 255,
							//chkbadchar:true,
							multi_dist_select: true,
							
							},
						'title': { 
							required: true,
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,
						},
						'field_anntothers[und][0][value]':{
							required: true,
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,							
							},
						'field_annstart[und][0][value][date]':{
							required: true,
							dateformat:true,
							date_notgreater_tdy:true,
							//date_greater_than:{ 'compar_id':'#edit-field-announcement-date-und-0-value2-datepicker-popup-0' },
							},
						'field_anndesc[und][0][value]':{
							required: true,
							maxlength: 500,
							chkbadchar:true,
							splchar:true,							
							},
						'field_annavail[und]': { 
							required: true,
							maxlength: 200,
							chkbadchar:true,
						},
						
						'field_annurl[und][0][value]':{
							required: "#edit-field-annavail-und-onlineavailable:checked",
							url: true,
							chkbadchar:true,

						},
						'files[field_anndown_und_0]':{
							required: "#edit-field-annavail-und-downloadable:checked",
							chkfile_format_size: true,
						},
						'field_annkword[und][0][value]':{
							minlength: 5,
							maxlength: 255,
							chkbadchar:true,
							splchar:true,								
						},
						'field_ann_type[und]':{
						required:true,
						valuenotequals: '_none',
						},

						
						
						
					
					},
                    messages: {
						'field_anndept[und]':{
							required: 'Please Select Concerned Department',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar: 'insert, select, update, delete, drop, alter, change, modify not allowed.',
							valuenotequals: 'Please Select Concerned Department',
							},
							'field_ann_org[und]':{
							required: 'Please Select Organization',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar: 'insert, select, update, delete, drop, alter, change, modify not allowed.',	
							valuenotequals: 'Please Select Organisation Name',
							},
							'field_anndist[und][]':{
							required: 'Please Select Districts',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',	
							multi_dist_select: 'Please Select either All or Particular Districts',
							},
							'title': { 
							required:  'Please enter Title',
							minlength: 'Minimum 5 characters should be entered',
							maxlength: 'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',
							},
							'field_anntothers[und][0][value]':{
							required:  'Field Value is Required',
							minlength: 'Minimum 5 characters should be entered',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',						
							},
							'field_annstart[und][0][value][date]':{
							required:'Please enter Announcement Date',
							dateformat: 'Invalid Date format',
							date_notgreater_tdy: 'Announcement Start Date should not be greater than today date.',
							//date_greater_than:{ 'compar_id':'#edit-field-announcement-date-und-0-value2-datepicker-popup-0' },
							},
							'field_anndesc[und][0][value]':{
							required:'Please enter Description',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',					
							},
							'field_annavail[und]': { 
							required: 'Please select announcements available option',
							maxlength:  'Invalid option',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							},
							'field_annurl[und][0][value]':{
							required: "Please Enter URL",
							url: 'Not Valid URL',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',

							},
							'files[field_anndown_und_0]':{
							required: 'Please select upload file',
							chkfile_format_size: 'Invalid File Format',
							},
							'field_annkword[und][0][value]':{
							minlength: 'Minimum 5 characters should be entered',
							maxlength:  'Maximum 255 character only allowed',
							chkbadchar:'insert, select, update, delete, drop, alter, change, modify not allowed.',
							splchar:'Special Characters are not allowed',					
							},
							'field_ann_type[und]':{
							required:'Please Select the Category',
							valuenotequals: 'Select the Category',
							},
	
				}, 
					errorLabelContainer: "#errormsg_container",
					 //focusInvalid: false,
   					invalidHandler: function(form, validator) {
       
       					 if (!validator.numberOfInvalids())
								return;
						else{
							
							  announcement("#announcements-node-form").create_errormsg_container('errormsg_container','announcements-node-form');
						}
							
							announcement('html, body').animate({
								scrollTop: announcement(validator.errorList[0].element).offset().top - 100
							}, 1000);
							
						},
				

   
	});
 /*errorLabelContainer: "#announcements-node-form",
						wrapper: "li",
  
	});
/*  errorPlacement: function(error, element) {
        element = element.closest('li');
        element = element.children(':first-child');
        error.insertBefore(element);
        error.addClass('message');
        announcement(function() {                                 // my function
            var errorIndex = announcement(error).index('div');
            var errorId = 'errordiv' + errorIndex.toString();
            announcement(error).attr('id', errorId);
            announcement('.errorList').append('<li><a href="#' + errorId + '">' + announcement(error).text() + '</a></li>');
			announcement("#announcements-node-form").before(element);
        });    
    },
*/

//// Title Validation
//    announcement('#edit-title').rules("add", { 
//    		//notaccept: {'exp':"[a-zA-Z]+"},
//			chkbadchar: true,
//    		//required: true,
//         	minlength: 0,
//         messages: {
//            // required: "Title is required"  ,
//           // notaccept: 'Number is Not Allowed',
//			chkbadchar:'blah blah'
//         }
//        
//     });

            
});
